<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Requests\Api\DailyRecord\StoreRequest;
use App\Requests\Api\Employees\EmployeesClockRequest;
use App\Requests\Api\Employees\EmployeesListRequest;
use App\Requests\Api\Employees\LoginRequest;
use App\Requests\Api\School\ListRequest;
use App\Service\CommonService;
use App\Service\EmployeesService;
use App\Service\SchoolService;
use Illuminate\Http\Request;

class EmployeesController extends Controller
{
    protected $schoolService;
    protected $employeesService;

    public function __construct(
        SchoolService $schoolService,
        EmployeesService $employeesService
    ){
        $this->schoolService = $schoolService;
        $this->employeesService = $employeesService;
    }

    /******************** 机构端 *************************/


    /**
     * 员工列表
     * @param Request $request
     * @return false|string
     * @throws \App\Exceptions\CustomException
     */
    public function list(EmployeesListRequest $request){
        CommonService::reqLog($request);
        try{
            $params = request(['school_id','identity_id','page','page_count']);
            $employeesInfo = $this->employeesService->list($params);
        }catch (\Exception $exception){
            customError($exception->getMessage(),$exception->getCode());
        }
        return responseData($employeesInfo['data'] ?? []);
    }

    /**
     * 员工登录
     * @param LoginRequest $request
     * @return false|string
     * @throws \App\Exceptions\CustomException
     */
    public function login(LoginRequest $request){
        CommonService::reqLog($request);
        try{
            $params = request(['account','password']);
            $employeesInfo = $this->employeesService->login($params);
        }catch (\Exception $exception){
            customError($exception->getMessage(),$exception->getCode());
        }
        return responseData($employeesInfo);
    }

    /**
     * 员工打卡
     * @param LoginRequest $request
     * @return false|string
     * @throws \App\Exceptions\CustomException
     */
    public function clock(EmployeesClockRequest $request){
        CommonService::reqLog($request);
        try{
            $params = request(['lon','lat','location_message','clock_type']);
            $employeesInfo = $this->employeesService->clock($params);
        }catch (\Exception $exception){
            customError($exception->getMessage(),$exception->getCode());
        }
        return responseData($employeesInfo);
    }


}
